package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public class AddItemActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_item);
        initview();

    }

    public void initview() {
        Button button = findViewById(R.id.button2);
        EditText editText = findViewById(R.id.editText);
        EditText editText2 = findViewById(R.id.editText2);
        EditText editText3 = findViewById(R.id.editText3);
        EditText editText4 = findViewById(R.id.editText4);
        EditText editText5 = findViewById(R.id.editText5);
        EditText editText6 = findViewById(R.id.editText6);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = editText.getText().toString();
                String itemDesc = editText2.getText().toString();
                String itemRemark = editText3.getText().toString();
                String price = editText4.getText().toString();
                String id = editText5.getText().toString();
                String time = editText6.getText().toString();

                Map<String, String> map = new HashMap<>();
                map.put("itemName",name);
                map.put("itemDesc",itemDesc);
                map.put("itemRemark",itemRemark);
                map.put("initPrice",price);
                map.put("kindId",id);
                map.put("avail",time);
                try {
                    String result = OkHttpUtil.postRequest("http://172.18.85.254:8080/auction/api/items",map);
                    System.out.println(result);
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        });
    }
}
